package com.chenzhou.controller;

import com.chenzhou.entity.GoodsEntity;
import com.chenzhou.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("status")
public class GoodsStatusController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 查询所有下架商品
     * @param request
     * @param status
     * @return
     */
    @RequestMapping("/query_GoodsStatus0")
    public String query_GoodsStatus(HttpServletRequest request,Integer status){
        List<GoodsEntity> list = goodsService.queryGoodsEntityByStatus(0);
        request.setAttribute("menu","status0");
        request.setAttribute("glist",list);
        return "goods_status/show_goods";
    }

    /**
     * 查询所有上架商品
     * @param request
     * @param status
     * @return
     */
    @RequestMapping("/query_GoodsStatus1")
    public String query_GoodsStatus01(HttpServletRequest request,Integer status){
        List<GoodsEntity> list = goodsService.queryGoodsEntityByStatus(1);
        request.setAttribute("menu","status1");
        request.setAttribute("glist",list);
        return "goods_status/show_goods";
    }

    /***
     * 修改商品上架
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/modify_status0")
    public String mpdify_GoodsStatus0(HttpServletRequest request,Integer id){
       int a = goodsService.modify_goodsStatus(id,1);
        if(a>0) {
            return this.query_GoodsStatus(request,1);
        }else {
            return "forward:/error.jsp";
        }
    }

    /***
     * 修改商品下架
     * @param request
     * @param id
     * @return
     */
    @RequestMapping("/modify_status1")
    public String mpdify_GoodsStatus1(HttpServletRequest request,Integer id){
        int a = goodsService.modify_goodsStatus(id,0);
        if(a>0) {
            return this.query_GoodsStatus01(request,0);
        }else {
            return "forward:/error.jsp";
        }
    }
}
